﻿<cfscript>
/** 
* @hint "bookBase - 出版社名称唯一性验证"
*/ 

component 
	extends="MachII.framework.EventFilter" 
	displayname="acadmicManager.filters.book.publisherUniqueFilter" 
	output=false 
	{

	/*
	* @hint "Configures this filter as part of the Mach-II framework" 
	*/
	public void function configure() output=false {} 
	
	/*
	* @hint "Filters event and returns a boolean to Mach-II indicating whether or not the event queue should proceed.  If not, the event queue is cleared and a new event is announced."
	* 
	* @event "MachII Event Object"
	* @eventContext "MachII EventContext Object"
	*/
	public boolean function filterEvent ( required MachII.framework.Event event, required MachII.framework.EventContext eventContext ) output=false {

		var pubName = trim(event.getArg("Publisher"));
		var checkArray = "";
		var sql = queryObj = "";

		if ( len(pubName) ) {
			
			sql = "	SELECT
						p.pid
					FROM
						t_publisher p
					WHERE
						p.publisher = :pubName ";
			
			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "pubName", value = pubName, cfsqltype = "cf_sql_varchar");
			rs_check = queryObj.execute(sql = sql).getResult();

			if( rs_check.recordCount ){
				/* 如果已存在相同出版社 */
				event.setArg("publisherExistsID", arrayToList(rs_check["pid"]));
				event.setArg("TabID", "labPublisher");
				announceEvent("publisherExists", event.getArgs());
			}
			else {
				/* 如果出版社名称不存在 则继续 */
				return true;
			}
			
		}
		else {
			announceEvent("nullPublisher");
		}
		
		return false;
	}
	
}

</cfscript>